<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@include file="../common/NavigationLeft.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>二维码管理系统</title>
</head>
<body style="height: 100%">
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
    <!-- 	  <nav class="navbar  navbar-fixed-static" bo> -->
    <!-- 	  		<h5 style="font-size:20px"><b>资产列表</b></h5> -->
    <!-- 	  </nav> -->
    <h2 class="page-header">用户列表</h2>
        <div class="row m-b-sm m-t-sm">
            <div class="col-md-1">
                <a><button id="refresh" type="button" class="btn btn-default btn-sm">刷新</button></a>
            </div>
            <form class="form-horizontal" action="#"
                  method="post" id="searchForm">
                <div class="col-md-5">
                    <button class="btn btn-default btn-sm" type="button"
                            id="deleteMany_btn">删除</button>
                    <a href="toAddUser.action"><button type="button" class="btn btn-default btn-sm" id="entry_btn">添加</button></a>
                    <button type="button" class="btn btn-default btn-sm" id="batch_add_btn" onclick="batchAdd();">批量添加</button>
                    <button type="button" class="btn btn-default btn-sm" id="download_btn" onclick="download();">导出表格</button>
                </div>
                <div class="col-md-4 f-r">
                    <div class="input-group">
                        <input type="text" id="queryName" class="form-control" value="${queryName}" name="queryName"
                               placeholder="请输入用户名" style="height:30px;"> <span
                            class="input-group-btn"><button
                            class="btn btn-primary btn-sm" type="btn" id="search_btn">搜索</button> </span>
                    </div>
                </div>
                <input id="pageCurr_hi" name="pageSizeCurr" type="hidden" value="${pageSizeCurr}"/>
                <input id="pageAll_hi" name="pageSizeALL" type="hidden" value="${pageSizeALL}"/>
            </form>
        </div>
        <div class="placeholder"></div>
        <!-- 		<table id="" class="table table-striped" cellspacing="0" width="100%"> -->
        <form class="form-horizontal" action="" method="post" id="user_Form" target="_blank">
            <table id="dataTable" class="table table-bordered table-striped table-hover" cellspacing="0">
                <thead>
                <tr>
                    <th>
                        <input autocomplete="off" type="checkbox" id="CheckedAll"
                               onclick="checkAll()">
                    </th>
                    <th>用户名</th>
                    <th>角色</th>
                    <th>添加时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
            <%--<div class="form-inline">--%>
                <%--<ul class="pagination pull-left">--%>
                    <%--<li>第${pageSizeCurr}</li>--%>
                    <%--<li>/</li>--%>
                    <%--<li>${pageSizeALL}页</li>--%>
                    <%--<li>&nbsp</li>--%>
                    <%--<li>共${querySum}条记录</li>--%>
                <%--</ul>--%>
                <%--<ul class="pagination pull-right">--%>
                    <%--<li value=""><a>&laquo;</a></li>--%>
                    <%--<s:iterator value="pagingArr"--%>
                                <%--var="page" status="st">--%>
                        <%--<li value="${page}"><a >${page}</a></li>--%>
                    <%--</s:iterator>--%>
                    <%--<li value=""><a>&raquo;</a></li>--%>
                <%--</ul>--%>
            <%--</div>--%>
        </form>
</div>
<div id="batch_import" class="edit-detail layer_panel"
     style="height: 80px;display:none" >
    <form method="post" id="file_upload_form" class="m-t"
          action="fileInputAsset.action">
        <div class="form-group">
            <label class="col-sm-4 control-label"><span
                    class="text-danger">*</span>文件：</label>
            <input  class="row col-sm-6 control-label" type="file" name="fileName" id="file_input" />
        </div>
    </form>
</div>
<div class="edit-detail layer_panel" id="File_upload_panel" >
    <form action="/asset/addUserBatch.action" method="post" id="uploadFileForm" enctype="multipart/form-data">
        <div>
            <label class="col-sm-12 control-label">请选择文件</label>
        </div>
        <div class="col-sm-12">
            <s:file class="col-sm-12" type="file" name="file" id="file"
                    onchange="changeFileName()"></s:file>
        </div>
        <div style="display:none"><p class='col-sm-12' style='color:red'>请选择文件!</p></div>
        <input type="hidden" id="fileName" name="fileName" value="" />
    </form>
</div>
</body>
<script type="text/javascript">


    $(function(){
        var table ="";
        var tip="${tip}";
        if(tip!=""){
            layer.msg(tip,{area: ['300px','50px']});
        }

        $("#refresh").click(function () {
            location.reload();
        })


        //初始化表格

//        queryData = {
//                "queryName":$("#queryName").val()
//            }
//        table = $('#dataTable').DataTable({
//            "language" : {
//                    "url" : "/js/datatables/jquery.dataTables.zh"
//                },
//            "ajax": {
//                    type: 'POST',
//                    url: 'ajax_listUserData.action',
//                    data:queryData,
//                    //contentType: 'application/json',
//                    timeout:60000
//                },
//        });
        initTable();
        function initTable() {
            var temp = $("#searchTemp").val();
            $.fn.dataTable.ext.errMode = function(s,h,m){
                layer.alert('数据加载失败');
            }
            queryData = {
                "queryName":$("#queryName").val()
            }
            table = $('#dataTable').DataTable( {
                "destroy" : true,
                "paging" : true,
                "lengthChange" : true,
                "searching" : false,
                "ordering" : false,
                "info" : true,
                "autoWidth" : false,
                "Filter" : false,
                responsive : true,
                "pagingType" : "full_numbers",
                "dom" : 'rtilp',
                "language" : {
                    "url" : "/js/datatables/jquery.dataTables.zh"
                },
                "processing": true,
                "serverSide": true,
                "ajax": {
                    type: 'POST',
                    url: '/asset/ajax_listUserData.action',
                    data:queryData,
                    //contentType: 'application/json',
                    timeout:60000
                },
                "drawCallback":function () {
                    $("#search_btn").click(function () {
                        table.page(table.page()).draw(false);
                    });
                    $(".del_li").click(function() {
                        $.ajax({
                            type : 'POST',
                            url : 'ajax_deleteUser.action',
                            data : {
                                "id" : $(this).attr("id"),
                                "userStatus":"Deleted"
                            },
                            success : function(result) {
                                if (result == "success") {
                                    layer.msg('删除成功');
                                    table.page(table.page()).draw(false);
                                } else {
                                    layer.msg('删除失败');
                                    table.page(table.page()).draw(false);
                                }
                            }
                        });
                    });
                    $("#deleteMany_btn").click(function () {
                        var ids = [];
                        $("input[name=checkedIds]:checked").each(function () {
                            var id = $(this).val();
                            ids.push(id);
                        });
                        var idd= $("input[name=checkedIds]:checked").val();
                        $.ajax({
                            type : 'POST',
                            url : "ajax_deleteUserMany.action",
                            data:{
                                "ids":ids,
                            },
                            traditional:true,
                            success:function (result) {
                                if (result == "success") {
                                    layer.msg('删除成功');
                                    var pageNum = table.page();
                                    table.page(table.page()).draw(false);
                                } else {
                                    layer.msg('删除失败');
                                    table.page(table.page()).draw(false);
                                }
                            }
                        });
                    })
                    $("input[name=checkedIds]").click(function () {
                        var allboxNum = $("input[name=checkedIds]").length;
                        var disabledBoxNum = $("input[name=checkedIds][disabled=disabled]").length;
                        var checkedBoxNum = $("input[name=checkedIds]:checked").length;
                        if(allboxNum == (checkedBoxNum+disabledBoxNum)){
                            $("#CheckedAll").prop("checked",true);
                        }else{
                            $("#CheckedAll").prop("checked",false);
                        }
                    });
                    $("#queryName").keydown(function () {
                        var event = window.event || arguments.callee.caller.arguments[0];
                        if (event.keyCode == 13)
                        {
                            table.page(table.page()).draw(false);
                        }
                    });
                },
                "columns" : [
                    {
                        "data" : "id",
                        render: function(data,display,row) {
                            if(row.status=="Inner"){
                                return '<input  name="checkedIds" type="checkbox" disabled="disabled" value="'+ data+'">';
                            }else{
                                return '<input  name="checkedIds" type="checkbox" value="'+ data+'">';
                            }
                        }
                    },
                    {
                        "data" : "name",
                        render: function(data) {
                            return data;
                        }
                    },
                    {
                        "data" : "role",
                        render:function(data) {
                            if(data == "Admin"){
                                return "管理员";
                            }
                            if(data == "User"){
                                return "普通用户";
                            }

                        }
                    },
                    {
                        "data" : "addedTime",
                        render:function(data) {
                            return data;
                        }
                    },
                    {
                        "data" : function(data){
                            return '<div class="btn-group">'+
                                    '<button data-toggle="dropdown"'+
                                    'class="btn btn-primary btn-xs dropdown-toggle" type="button">'+
                                    '<i class="fa fa-cog"></i> 操作 <span class="caret"></span>'+
                                    '</button>'+
                                    '<ul class="dropdown-menu">'+
//                                    '<li><a class="" href="userInfo.action?id='+data.id+'">查看</a></li>'+
                                    '<li><a class="" href="toModifyAddUser.action?id='+data.id+'"'+
                                    '	onclick="">修改</a></li>'+
                                    '<li><a class="del_li" href="javascript:void(0);"'+
                                    ' id="'+data.id+'">删除</a></li>'+
                                    '</ul>'+
                                    '</div>';
                        }
                    }

                ]
            } );
            return table;
        }
        //////////////////////


    });


    function download(){
        window.location.href="exportUserExcel.action";
    }
    function changeFileName(){
        var filePath = $("#file").val();
        var fileName = filePath.substring(filePath.lastIndexOf("\\") + 1);
        $("#fileName").val(fileName);
        $("#file").parent().next().hide();
    }

function checkAll() {
    if ($("#CheckedAll").prop("checked")) {
        $(":checkbox").prop("checked", true);
        $("input[name=checkedIds][disabled=disabled]").prop("checked", false);
    } else {
        $(":checkbox").prop("checked", false);
    }
}

    $("#batch_add_btn").click(function(){
        layer.open({
            title: '文件批量导入',
            type: 1,
            area: ['400px','200px'],
            content: $("#File_upload_panel"),
            btn: ['确定', '取消'],
            yes: function(index, layero) {
                layer.close(index);
                if($("#file").val()!=''){
                    $("#uploadFileForm").submit();
                }
                else{
                    $("#file").parent().next().show();
                }
            },
            cancel: function(index) {}
        });
    });
</script>
</html>